<%@include file="head.jsp" %>	
<%@include file="nav.jsp" %>

	
<div id="content_test_url">

	<h1>Testeando la URL de Google con java</h1>
	<%@page import="java.net.*" %>
	<%@page import="java.io.*" %>
	<%
		 URL myURL = new URL("https://www.google.es/");	
	%>
	
	<ol>
		<li>
			<span>url:</span>
			<span class="valor"><%=myURL %></span>
		</li>
		<li>
			<span>host:</span>
			<span class="valor"><%=myURL.getHost()%></span>
		</li>
		<li>
			<span>port:</span>
			<span class="valor"><%=myURL.getPort()%></span>
		</li>
		<li></li>
		<li></li>
	</ol>
	
	<div class="content_html">
	<%
    try {
        
        DataInputStream dis = new DataInputStream(myURL.openStream());
        String inputLine;

        while ((inputLine = dis.readLine()) != null) {
        	inputLine = inputLine.replace("/images/srpr/logo1w.png", "https://www.google.com/images/srpr/logo1w.png");
        	out.print(inputLine);
        }
        dis.close();
        
    	java.net.URLConnection con = myURL.openConnection();
    	InputStream s = con.getInputStream();
    	BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(s));
    	String line = "";
    	
    	while((line = bufferedReader.readLine())!=null){
    		line = line.replace("/images/srpr/logo1w.png", "https://www.google.com/images/srpr/logo1w.png");
    		out.print(line);
    	}
    	
    	
    } catch (MalformedURLException me) {
        System.out.println("MalformedURLException: " + me);
    } catch (IOException ioe) {
        System.out.println("IOException: " + ioe);
    }
	%>
		
	</div>

</div>

<%@include file="footer.jsp" %>		